// index.js
import { createRouter, createWebHistory ,createWebHashHistory } from 'vue-router'
import App from '@/App.vue'

// 路由规则
const routes = [
    {
        path: '/',
        component: App,
        children: [
            { path: '' , redirect: {name: 'Index'} },
            {
                path: '/index',
                name: 'Index',
                component: () => import('@/views/index.vue'),
                meta: {
                    title: 'Welcome',
                    hasRouteBack: false,
                }
            },
            {
                path: '/register',
                name: 'Register',
                component: () => import('@/views/register/register.vue'),
                meta: {
                    title: 'Register',
                    hasRouteBack: false,
                }
            },
            {
                path: '/regPassword',
                name: 'RegPassword',
                component: () => import('@/views/register/regPassword.vue'),
                meta: {
                    title: 'Register',
                    hasRouteBack: false,
                }
            },
            {
                path: '/regCode',
                name: 'RegCode',
                component: () => import('@/views/register/regCode.vue'),
                meta: {
                    title: 'Register',
                    hasRouteBack: false,
                }
            },
            {
                path: '/login',
                name: 'Login',
                component: () => import('@/views/login.vue'),
                meta: {
                    title: 'Login',
                    hasRouteBack: false,
                }
            },
            {
                // vue-router@4的变化，舍弃*通配符
                // 官方文档：https://next.router.vuejs.org/zh/guide/migration/index.html#%E5%88%A0%E9%99%A4%E4%BA%86-%EF%BC%88%E6%98%9F%E6%A0%87%E6%88%96%E9%80%9A%E9%85%8D%E7%AC%A6%EF%BC%89%E8%B7%AF%E7%94%B1
                path: '/:pathMatch(.*)*',
                name: 'error',
                component: () => import('@/views/error.vue'),
                meta: {
                    title: 'Error'
                }
            }
        ]
    },
    {
        path: '/account',
        name: 'Account',
        component: () => import('@/views/account/index.vue'),
        meta: {
            title: 'Account',
            hasRouteBack: false,
            activeName: 'Account',
        },
    },
    {
        path: '/address',
        name: 'Address',
        component: () => import('@/views/account/address/index.vue'),
        meta: {
            title: 'Address',
            hasRouteBack: true,
            activeName: 'Account',
            hasClickByFun: true,
        },
    },
    // {
    //     path: '/editAddress',
    //     name: 'EditAddress',
    //     component: () => import('@/views/account/address/edit.vue'),
    //     meta: {
    //         title: 'New Addresses',
    //         hasRouteBack: true,
    //         activeName: 'Account',
    //     },
    // },
    {
        path: '/profile',
        name: 'Profile',
        component: () => import('@/views/account/profile/profile.vue'),
        meta: {
            title: 'Profile',
            hasRouteBack: true,
            activeName: 'Account',
        },
    },
    {
        path: '/order',
        name: 'Order',
        component: () => import('@/views/account/order/index.vue'),
        meta: {
            title: 'Order',
            hasRouteBack: true,
            activeName: 'Account',
        },
    },
    {
        path: '/payment',
        name: 'PayMent',
        component: () => import('@/views/account/payment/payment.vue'),
        meta: {
            title: 'PayMent',
            hasRouteBack: true,
            activeName: 'Account',
        },
    },

    {
        path: '/cart',
        name: 'Cart',
        component: () => import('@/views/cart/cart.vue'),
        meta: {
            title: 'Cart',
            hasRouteBack: false,
            activeName: 'Cart',
        },
    },
    {
        path: '/explore',
        name: 'Explore',
        component: () => import('@/views/explore/explore.vue'),
        meta: {
            title: 'Explore',
            hasRouteBack: false,
            activeName: 'Explore',
        },
    },
    {
        path: '/favorite',
        name: 'Favorite',
        component: () => import('@/views/favorite/favorite.vue'),
        meta: {
            title: 'Favorite',
            hasRouteBack: false,
            activeName: 'Favorite',   
        }
    },
    {
        path: '/shop',
        name: 'Shop',
        component: import('@/views/shop/index.vue'),
        meta: {
            title: 'Lungangen',
            hasRouteBack: false,
            hasIcon: true,
            activeName: 'Shop',    
        }
    },
    {
        path: '/shopDetail',
        name: 'ShopDetail',
        component: import('@/views/shop/detail.vue'),
        meta: {
            title: '',
            hasRouteBack: true,
            hasIcon: false,
            activeName: 'Shop',    
        }
    },
]

const router = createRouter({
    // vueRouter@3版本的mode改成了history，hash模式配置createWebHashHistory，history模式配置createWebHistory
    history: createWebHistory(),
    routes
})

export default router